using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using DAL;
using BUS;
public partial class SanPham_sanphamtheodanhmuc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddt();
        }
    }

    public void loaddt()
    {
        int iD = int.Parse(Request.QueryString["id"].ToString());
        int h = 0;
        dtlvip.DataSource = tbSanPhamBUS.Get(" Where tinhtrang = '2' and danhmuc= " + iD.ToString(), Pager.CurrentIndex, Pager.PageSize, tbSanPhamColumns.masp.ToString(), "DESC", out h);
        dtlvip.DataBind();
        Pager.ItemCount = h;
        if (h < Pager.PageSize)
        {
            Pager.Visible = false;
        }
    }

    protected void dtlvip_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HyperLink hpten = (HyperLink)e.Item.FindControl("hpten");
            Label lb_dacdiem = (Label)e.Item.FindControl("lb_dacdiem");
            Label lb_gia = (Label)e.Item.FindControl("lb_gia");
            Label lb_giagoc = (Label)e.Item.FindControl("lb_giagoc");
            Label lb_soluong = (Label)e.Item.FindControl("lb_soluong");
            Label lb_thoigian = (Label)e.Item.FindControl("lb_thoigian");
            Label lb_soluongconlai = (Label)e.Item.FindControl("lb_soluongconlai");
            Image hinh = (Image)e.Item.FindControl("hinh");
            tbSanPham sp = (tbSanPham)e.Item.DataItem;
            tbHinhAnh hinhanh = tbHinhAnhBUS.GetByID(sp.masp);

            hpten.Text = sp.tensp.ToString();
            hpten.NavigateUrl = "chitietsanpham.aspx?masp=" + sp.masp.ToString();
            lb_dacdiem.Text = sp.mota.ToString();
            lb_gia.Text = sp.giaban.ToString();
            lb_giagoc.Text = sp.giagoc.ToString();
            TimeSpan ngay = sp.ngaysudung.Subtract(DateTime.Parse(DateTime.Now.ToShortDateString()));
            lb_thoigian.Text = ngay.TotalDays.ToString();
            lb_soluong.Text = sp.soluongban.ToString();
            lb_soluongconlai.Text = sp.soluongtoida.ToString();
            hinh.ImageUrl = "~/Photos/Thumb/" + hinhanh.hinhminhhoa.ToString();
        }
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        loaddt();
    }
}
